package com.tzpay.tzpay.common;

import com.tzpay.tzpay.utils.T;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Headers;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by chenfeiyue on 16/3/11.
 */
public class NormalCallBack implements okhttp3.Callback {

    private static final String TAG = NormalCallBack.class.getSimpleName();

    @Override
    public void onFailure(Call call, IOException e) {
        e.printStackTrace();
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
        if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

        Request request = call.request();
        T.e(TAG, "===========onResponse  start  =============" + request.url() + "   method = " + request.method());
        Headers responseHeaders = response.headers();
        for (int i = 0, size = responseHeaders.size(); i < size; i++) {
            T.e(TAG, "===========" + responseHeaders.name(i) + ": " + responseHeaders.value(i));
        }
        T.e(TAG, "===========response.body().string() = " + response.body().string());
        T.e(TAG, "===========onResponse  end  =============");
    }
}
